<?
// If data is set (i.e the submit button has been hit) and $action != 'newaccount' (setup exception)
if (isset($data) AND $action != 'newaccount') {
	if (is_array($data)) {
		
		// HARDCODED $data['id'], $data['type'];
		$data['id'] = $resellerdata['id'];
		$data['type'] = 'domain';
		
		if ($cfg['bandwidth'] && $data['bandwidth'] != 0 && $resellerdata['bandwidth'] != 0 && $data['bandwidth'] > $resellerdata['bandwidth']) {
			$data['bandwidth'] = $resellerdata['bandwidth'];
		}
		
		$error = domain("create",$data,$return);
		if ($error)
			echo "<br>&nbsp;&nbsp;� ".implode("<br>\n&nbsp;&nbsp;� ",$error)."<br>\n";
		else
			echo "<br><div align='center'>".$T['domain created']."<a href='./?cp=domain&url=newuser&number=$return' target='_top'><b>".$data['hostname'].".".$data['domain']."</b></a>.</div><br>\n";
	}
}
if (isset($package)) {
	$SQL = "SELECT id, name, description, pointers, subdomains, users, hd, transfer, bandwidth, serverside, `databases`, shell FROM packages WHERE id = ".$package." and ownerid = '".$resellerdata['id']."'";
	$package = mysql_query($SQL);
	$data = mysql_fetch_array($package);
	$sslangarray = explode(",", $data['serverside']);
	unset($data['serverside']);
	if (strstr($cfg['sslang'],",")) $sslang = explode(",",$cfg['sslang']);
	else $sslang[0] = $cfg['sslang'];
	for ($i=0; $i<sizeOf($sslang); $i++) {
		$data['serverside'][trim($sslang[$i])] = $sslangarray[$i];
	}
}
?>
<div align="center">
<form action="<?=$current_url;?>" method="post" name="webcp" onSubmit="submitonce(this);">
<table border="0" cellpadding="0" cellspacing="0"><tr><td>
<table border="0" cellpadding="0" cellspacing="0" class="tblbg"><tr><td>
<table border="0" cellspacing="1">
	<tr>
		<td colspan="2" class="tbltop">&nbsp;<?=$T['menu'][$url];?>&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['IP Address'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<select name="data[ip_addr][]" multiple size=3>
		<?
		$tmp = explode(" ",$resellerdata['ip']);
		$i = 0;
		do {
			echo '<option value="'.trim(current($tmp)).'"';
			if (is_array($data['ip_addr'])) {
				foreach($data['ip_addr'] as $key =>$val) {
					if (strstr($val, current($tmp))) echo " SELECTED";
				}
			} else if ($i == 0) { 
				echo " SELECTED";
			}
			echo '> '.current($tmp).'</option>';
			echo "\n";
			$i++;
		} while(next($tmp));
	
		?></select>&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Hostname'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[hostname]" size="25" maxlength="255" value="<? if(!$data['hostname']) echo "www"; else echo $data['hostname'];?>">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Domain Name'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[domain]" size="25" maxlength="255" value="<?=$data['domain'];?>">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Hostname Aliases'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[aliases]" size="25" maxlength="255" value="<?=$data['aliases'];?>">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Default Root'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[defaultroot]" size="25" maxlength="255" value="<? if($data['defaultroot']) echo $data['defaultroot']; else echo "/web/%USER%";?>">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Domain Alias'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="checkbox" name="data[nohost]" value="true" CHECKED>&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Catch all Aliases'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="checkbox" name="data[catchall]" value="true">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Redirect'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="checkbox" name="data[redirect]" value="true" CHECKED>&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Sub Domain Mail'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="radio" name="data[sdmail]" value="true">&nbsp;<?=$T['Yes'];?>&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="data[sdmail]" value="false" checked>&nbsp;<?=$T['No'];?>&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="data[sdmail]" value="both">&nbsp;<?=$T['Both'];?>&nbsp;</td>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Num Users'];?>&nbsp;</b></td>
		<? if ($resellerdata['users'] != -1) { ?>
			<td class="row2">&nbsp;<input type="text" name="data[users]" size="5" maxlength="255" value="<? if($data['users']) echo intval($data['users']); else echo 10;?>">&nbsp;</td>
		<? } else { ?>
			<td class="row2">&nbsp;<input type="text" name="data[users]" size="5" maxlength="255" value="<? if ($data['users'] != -1) if(isset($data['users'])) echo intval($data['users']); else echo 10;?>" id="users" onchange="document.getElementById('usercheck').checked = false;">&nbsp;<input type=checkbox id="usercheck" name="data[users]" value="-1" onclick="document.getElementById('users').value = '';" <? if ($data['users'] == -1) echo "checked";?>><?=$T['Unlimited'];?></td>
		<? } ?>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['HD Quota'];?>&nbsp;</b></td>
		<? if ($resellerdata['hd'] != -1) { ?>
			<td class="row2">&nbsp;<input type="text" name="data[hd]" size="5" maxlength="255" value="<? if($data['hd']) echo intval($data['hd']); else echo 50;?>"> <?=$T['mb'];?>&nbsp;</td>
		<? } else { ?>
			<td class="row2">&nbsp;<input type="text" name="data[hd]" size="5" maxlength="255" value="<? if ($data['hd'] != -1) if(isset($data['hd'])) echo intval($data['hd']); else echo 50;?>" id="hd" onchange="document.getElementById('hdcheck').checked = false;"> <?=$T['mb'];?> &nbsp;<input type=checkbox id="hdcheck" name="data[hd]" value="-1" onclick="document.getElementById('hd').value = '';" <? if ($data['hd'] == -1) echo "checked";?>><?=$T['Unlimited'];?></td>
		<? } ?>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Num Subdomains'];?>&nbsp;</b></td>
		<? if ($resellerdata['subdomains'] != -1) { ?>
			<td class="row2">&nbsp;<input type="text" name="data[subdomains]" size="5" maxlength="255" value="<? if(isset($data['subdomains'])) echo intval($data['subdomains']); else echo 2;?>">&nbsp;</td>
		<? } else { ?>
			<td class="row2">&nbsp;<input type="text" name="data[subdomains]" size="5" maxlength="255" value="<? if ($data['subdomains'] != -1) if($data['subdomains']) echo intval($data['subdomains']); else echo 2;?>" id="subdomains" onchange="document.getElementById('subdomaincheck').checked = false;">&nbsp;<input type=checkbox id="subdomaincheck" name="data[subdomains]" value="-1" onclick="document.getElementById('subdomains').value = '';" <? if ($data['subdomains'] == -1) echo "checked";?>><?=$T['Unlimited'];?></td>
		<? } ?>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Num Pointers'];?>&nbsp;</b></td>
		<? if ($resellerdata['pointers'] != -1) { ?>
			<td class="row2">&nbsp;<input type="text" name="data[pointers]" size="5" maxlength="255" value="<? if(isset($data['pointers'])) echo intval($data['pointers']); else echo 1;?>">&nbsp;</td>
		<? } else { ?>
			<td class="row2">&nbsp;<input type="text" name="data[pointers]" size="5" maxlength="255" value="<? if ($data['pointers'] != -1) if($data['pointers']) echo intval($data['pointers']); else echo 1;?>" id="pointers" onchange="document.getElementById('pointercheck').checked = false;">&nbsp;<input type=checkbox id="pointercheck" name="data[pointers]" value="-1" onclick="document.getElementById('pointers').value = '';" <? if ($data['pointers'] == -1) echo "checked";?>><?=$T['Unlimited'];?></td>
		<? } ?>
	</tr>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Num Databases'];?>&nbsp;</b></td>
		<? if ($resellerdata['db'] != -1) { ?>
			<td class="row2">&nbsp;<input type="text" name="data[databases]" size="5" maxlength="255" value="<? if(isset($data['databases'])) echo intval($data['databases']); else echo 5;?>">&nbsp;</td>
		<? } else { ?>
			<td class="row2">&nbsp;<input type="text" name="data[databases]" size="5" maxlength="255" value="<? if ($data['databases'] != -1) if(isset($data['databases'])) echo intval($data['databases']); else echo 5;?>" id="databases" onchange="document.getElementById('databasecheck').checked = false;">&nbsp;<input type=checkbox id="databasecheck" name="data[databases]" value="-1" onclick="document.getElementById('databases').value = '';" <? if ($data['databases'] == -1) echo "checked";?>><?=$T['Unlimited'];?></td>
		<? } ?>
	</tr>
	<?
			$ret = Array('data' => $data, 'userdata' => $userdata, 'entries' => Array());
			call_hook('web:reseller:newdomain:table', $ret);
			if (is_array($ret['entries'])) {
			foreach($ret['entries'] as $item) {
			?>
			<tr>
				<td class="row1"><b>&nbsp;<?=$item['name'];?>&nbsp;</b></td>
				<td class="row2">&nbsp;<?=$item['value'];?>&nbsp;</td>
			</tr>
			<?
			}
			}
			?>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Server Side Options'];?>&nbsp;</b></td>
		<td class="row2"><table border="0" cellpadding="0" cellspacing="0">
		<?
		if (strstr($cfg['sslang'],",")) $sslang = explode(",",$cfg['sslang']);
		else $sslang[0] = $cfg['sslang'];

		$j = 0;
		while ($sslang[$j]) {
			echo "<tr><td class='row2'>&nbsp;".$T['ss'][trim($sslang[$j])]."&nbsp;</td><td class='small'>\n";
			if ($resellerdata['serverside'][trim($sslang[$j])] != "on")
				echo '&nbsp;<input type="radio" name="data[serverside]['.trim($sslang[$j]).']" value="na" CHECKED>'.$T['na'];
			else {
				echo '&nbsp;<input type="radio" name="data[serverside]['.trim($sslang[$j]).']" '.(($data['serverside'][trim($sslang[$j])] == "na") ? "checked" : "").' value="na">'.$T['na'];
				echo '&nbsp;<input type="radio" name="data[serverside]['.trim($sslang[$j]).']" '.(($data['serverside'][trim($sslang[$j])] == "on") ? "checked" : "").' value="on">'.$T['on'];
				echo '&nbsp;<input type="radio" name="data[serverside]['.trim($sslang[$j]).']" '.(($data['serverside'][trim($sslang[$j])] == "off") ? "checked" : "").' value="off">'.$T['off'];
			}
			echo "\n</td></tr>\n";
			++$j;
		}
	?>
	
	</table></tr>
	<?
	if ($resellerdata['shell'] == "on") {
		?>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Shell Access'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="radio" name="data[shell]" value="on" <?=(($data['shell'] == "on") ? "checked" : "");?>><?=$T['on'];?>
		<input type="radio" name="data[shell]" value="off" <?=(($data['shell'] == "off") ? "checked" : "");?>><?=$T['off'];?>&nbsp;</td>
	</tr>
	<? } ?>
	<tr>
		<td class="row1"><b>&nbsp;<?=$T['Domain Contact E-Mail'];?>&nbsp;</b></td>
		<td class="row2">&nbsp;<input type="text" name="data[email]" size="25" maxlength="255" value="<?=$data['email'];?>">&nbsp;</td>
	</tr>
</table>
</td></tr></table><br>
<div align="right"><input type="submit" value="<?=$T['submit'];?>"></div>
</td></tr></table>
</form>
</div>
